<?php

class m120620_113839_alter_employee extends EDbMigration {

	public function safeUp() {
		$models = Employee::model()->findAll();
		foreach ($models as $model) {
			if (!$model->residentId) continue;
			
			$identity = new Identity;
			$identity->employeeId = $model->id;
			$identity->name = 'KTP';
			$identity->code = $model->residentId;
			$identity->createdBy = 1;
			$identity->updatedBy = 1;
			$identity->save();
		}
		$this->dropColumn('employees', 'residentId');
	}

	public function safeDown() {
		$this->addColumn('employees', 'residentId', 'varchar(32)');
	}

}